module.exports = {
  description: '创建页面',
  prompts: [
    {
      type: 'confirm',
      name: 'useSetUp',
      message: '是否使用setup语法糖',
      default: false,
    },
    {
      type: 'input',
      name: 'path',
      message: '请输入模块名称(例如 newModule 将新建于pages文件夹下)',
    },
    {
      type: 'input',
      name: 'name',
      message: '请输入文件名',
      validate: (v) => {
        if (!v || v.trim === '') {
          return '文件名不能为空';
        }

        return true;
      },
    },
  ],
  actions: (data) => {
    const actions = [];
    if (!data.useSetUp) {
      actions.push(
        {
          type: 'add',
          path: 'src/pages/{{path}}/{{name}}/index.vue',
          templateFile: 'plop-templates/page/notUseSetUpIndex.hbs',
          data: {
            componentName: `${data.name}`,
          },
        },
        {
          type: 'add',
          path: 'src/pages/{{path}}/{{name}}/ts/index.ts',
          templateFile: 'plop-templates/page/ts.hbs',
          data: {
            pathName: `${data.path}`,
            componentName: `${data.name}`,
          },
        },
        {
          type: 'add',
          path: 'src/pages/{{path}}/{{name}}/index.scss',
          templateFile: 'plop-templates/page/scss.hbs',
          data: {
            componentName: `${data.name}`,
          },
        },
        {
          type: 'add',
          path: 'src/pages/{{path}}/{{name}}/type.ts',
          templateFile: 'plop-templates/page/type.hbs',
          data: {
            componentName: `${data.name}`,
          },
        },
      );
    } else {
      actions.push(
        {
          type: 'add',
          path: 'src/pages/{{path}}/{{name}}.vue',
          templateFile: 'plop-templates/page/index.hbs',
          data: {
            componentName: `${data.path}`,
          },
        },
        {
          type: 'add',
          path: 'src/pages/{{path}}/type.ts',
          templateFile: 'plop-templates/page/type.hbs',
          data: {
            componentName: `${data.path}`,
          },
        },
      );
    }
    return actions;
  },
};
